<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/table.css" rel="stylesheet" type="text/css" />
<link href="css/excite-bike/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/jquery-ui-1.8.22.custom.min.js"></script>
<style type="text/css">
th.forLogin {
	color: #FFFFFF;
	font-family: Arial;
	font-size: 125%;
	background-color: #6699FF;
}

td.TRTable_Record_h_1 { 
  	background-color: #FFA500;
}
td.TRTable_Body { 
  	text-align:center; 
}


.FillinTRTable_b { 
  	text-align:center; 
}
.FillinTRTable_l_2 { 
	border-right-style:solid;
}
.FillinTRTable_l_1 { 
	border-top-style:solid;
}
  
table.FillinTRTable {
	border-style:solid;
	border-color:#000000;
} 


.messageText {
	color: blue;
	font-weight: bolder;
}
</style>

<script type="text/javascript">

	/**
	* 回傳按鈕的HTML語法
	* 為了建構出不同工作都可以使用的按鈕
	* 所以要填入 所有工作需要的變數聯集
	**/
	function but(taskDefinitionKey,processInstanceID, mrid, taskID,ori_performerId,ver_d) {
		var strOne = "";	//按鈕上文字，讓使用者知道這筆工作的目的
		
		if(taskDefinitionKey == "dispatchTask") {	//指派測試工作
			strOne = "指派測試人員";
		} else if(taskDefinitionKey == "submitTC") { //送審測試案例
			strOne = "選擇測試案例";
		} else if(taskDefinitionKey == "reviewTC") { //檢視測試案例
			strOne = "檢視測試案例";
		} else if(taskDefinitionKey == "reviewTR") { //檢視測試結果
			strOne = "檢視測試結果";
		} else if(taskDefinitionKey == "submitTR") { //檢視測試案例
			strOne = "輸入測試結果";
		}
		var str = "<button type=\"button\" onclick=\"butClick(this,'"+taskID+"','"+mrid+"','"+processInstanceID+"','"+taskDefinitionKey+"','"+ori_performerId+"','"+ver_d+"')\" butValue=\"\" content=\"\" previousAssignee=\"\" id=\"but_"+ taskID + "\">"+strOne+"</button>";
		return str;
	}
	
	/** 檢查有沒有沒勾檢查通過的 **/
	function submitTR_CheckChkbox() {
		var isCheck = true;
		$(".isPass").each(function() {
			if (!$(this).prop("checked")) {
				isCheck = false;
			}
		});
		return isCheck;
	}
	
	function selectTC(tcID) {
		var content = "將送審"+tcID;
		var taskID = $("#activeTaskID")[0].value;
		$("#but_" + taskID).html(content);
		$("#but_" + taskID).attr("butValue",content);
	}
	
	
	/** 送審測試結果 **/
	function submitTR(mrid,TaskID) {
		$("#trMRID")[0].value = mrid;
		$("#trUser")[0].value = $.cookie("userID");
		$("#trTaskID")[0].value = TaskID;
		$("#trNumSN")[0].value = $(".resultBody").size();	//記錄到底有幾次的測試結果 
		$.ajax({
			type : "post",
			url : "SubmitTR",
			data : $("#tr_Form").serializeArray(),
			dataType : "text",
			success : function(submitResult) {
				$("#but_" + taskID).html("已提交送審");
				$("#but_" + taskID).button({disabled : true});
			}, error : function(xhr, ajaxOptions, thrownError) {
				$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
				$("#errorMessage").append(xhr.responseText);
			}
		});
	}
	
	function conditionTR(mrid,taskID,condition,assignedTester) {
		$("#submitMRID")[0].value = mrid;
		$("#submitTaskID")[0].value = taskID;
		$("#submitCondition")[0].value = condition;
		$("#submitAssignedTester")[0].value = assignedTester;
		$("#submitComment")[0].value = $("#reviewTR_Comment").val();
	 	x = $("#submitForm").serializeArray();
		$.ajax({
			type : "post",
			url : "ReviewTR_02",
			data : x,
			dataType : "text",
			success : function(ReviewTC_02Result) {
			}, error : function(xhr, ajaxOptions, thrownError) {
				$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
				$("#errorMessage").append(xhr.responseText);
			}
		}); 
	}
	
	function conditionTC(mrid,ver_d,taskID,condition,assignedTester) {
		$("#submitMRID")[0].value = mrid;
		$("#submitVer_d")[0].value = ver_d;
		$("#submitTaskID")[0].value = taskID;
		$("#submitCondition")[0].value = condition;
		$("#submitAssignedTester")[0].value = assignedTester;
		$("#submitComment")[0].value = $("#reviewTC_Comment").val();
	 	x = $("#submitForm").serializeArray();
		$.ajax({
			type : "post",
			url : "ReviewTC_02",
			data : x,
			dataType : "text",
			success : function(ReviewTC_02Result) {
			}, error : function(xhr, ajaxOptions, thrownError) {
				$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
				$("#errorMessage").append(xhr.responseText);
			}
		}); 
	}
	
	function ValidateNumber(e, pnumber)
    {
		if (!/^\d+$/.test(pnumber)) {
        	var newValue =/^\d+/.exec(e.value);         
			if (newValue != null) {             
            	e.value = newValue;        
            } else {          
            	e.value = "";    
            } 
        }
        return false;
    }
	
	function butClick(self,taskID,mrid,processInstanceID,taskDefinitionKey,ori_performerId,ver_d) {
		/** 先找出這筆MRID所對應送審的測試案例，顯示出來 **/
		$("#submitMRID")[0].value = mrid; //為了要找TestCase的資料，我們要給它MRID才能去Mapping Table中找
		
		if(taskDefinitionKey == "reviewTC") {	//檢視測試案例
			var assignedTester = $("#but_"+taskID).prop("previousAssignee");
			//先清空舊有資料
			$("#ReviewTCTable_b").html("");
			x = $("#submitForm").serializeArray();
			$.ajax({
				type : "post",
				url : "ReviewTC_01",
				data : x,
				dataType : "JSON",
				success : function(ReviewTC_01Result) {
					$.each(ReviewTC_01Result, function(i, res) {
						$("#ReviewTCTable_b").append(
								"<tr bgcolor=\"FFFFFF\"><td>" + res.tcID
										+ "</td><td>" + res.tcName
										+ "</td><td>" + res.tcKeyPoint
										+ "</td><td>" + res.tcProcess
										+ "</td><td>" + res.tcResExp
										+ "</td><td>" + res.CreatedDateTime
										+ "</td><td>" + res.Creator
										+ "</td></tr>");
					});
					$("#dialog-ReviewTC").css("visibility", "visible");
					$("#dialog-ReviewTC").dialog({
						resizable : true,
						width : 800,
						height : 400,
						modal : true,
						buttons : {
							"同意" : function() {
								$("#but_"+taskID).html("同意!!");	//Button改變值，要用.html, Input的Button用prop
								$("#but_"+taskID).button({ disabled: true });
								conditionTC(mrid,ver_d,taskID,"2",assignedTester);
								$(this).dialog("close");
							},
							"拒絕" : function() {
								$("#but_"+taskID).html("拒絕!!");
								$("#but_"+taskID).button({ disabled: true });
								conditionTC(mrid,ver_d,taskID,"1",assignedTester);
								$(this).dialog("close");
							},
							"返回" : function() {
								$(this).dialog("close");
							}
						}
					});
					$("#dialog:ui-dialog").dialog("destroy");
				}, error : function(xhr, ajaxOptions, thrownError) {
					$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
					$("#errorMessage").append(xhr.responseText);
				}
			});
		} else if (taskDefinitionKey == "reviewTR")  {	//檢視測試結果
			$("table[id=ReviewTRTable] thead").remove();		//先清空查詢結果，避免關閉Dialog後，再打開Dialog時，先前的東西還在
			$("table[id=ReviewTRTable] tbody").remove();		//先清空查詢結果，避免關閉Dialog後，再打開Dialog時，先前的東西還在
			x = $("#submitForm").serializeArray();
			$.ajax({
				type : "post",
				url : "ReviewTR_01",
				data : x,
				dataType : "JSON",
				success : function(ReviewTR_Result) {
					$.each(ReviewTR_Result, function(i, res) {
						$("#ReviewTRTable").append(
								"<thead id=\"ReviewTRTable_"+i+"_h\"><tr>"
								+ "<th>案例ID</th><th>案例名稱</th><th colspan=\"3\">驗証重點</th><th colspan=\"3\">測試程序</th><th colspan=\"2\">預期結果</th></tr>"
								+ "<tr bgcolor=\"FFFFFF\"><td>" + res.submittedTestCase.tcID
								+ "</td><td>" + res.submittedTestCase.tcName
								+ "</td><td colspan=\"3\">" + res.submittedTestCase.tcKeyPoint
								+ "</td><td colspan=\"3\">" + res.submittedTestCase.tcProcess
								+ "</td><td colspan=\"2\">" + res.submittedTestCase.tcResExp
								+ "</td></tr></thead>"
								+ "<tbody id=\"ReviewTRTable_"+i+"_b\" >"
								+ "<tr class=\"FillinTRTable_l_1\"><td>提出人："+res.submittedTestCase.Creator+"</td><td>"									
								+ "<td class=\"TRTable_Record_h_1\">結果</td>"
								+ "<td class=\"TRTable_Record_h_1\">合計</td>"
								+ "<td class=\"TRTable_Record_h_1\">&nbsp;</td>"
								+ "<td class=\"TRTable_Record_h_1\">&nbsp;</td>"
								+ "<td class=\"TRTable_Record_h_1\">&nbsp;</td>"
								+ "<td class=\"TRTable_Record_h_1\">&nbsp;</td>"
								+ "<td class=\"TRTable_Record_h_1\">&nbsp;</td>"
								+ "<td class=\"TRTable_Record_h_1\">&nbsp;</td></tr>"
								+ "<tr><td bgcolor=\"FFFFFF\" colspan=\"2\" >" + res.comment + "</td>"
								+ "<td>&nbsp;</td><td>#</td><td>缺失數</td><td>驗證重點數</td><td>成功數</td><td>失敗數</td><td>無法測試數</td><td>待測試數</td></tr>"
							);
						$.each(res.submittedTestRecords, function(j, res_record) {
							var bgcolor="#CCCCCC";
							if ((j+1) % 2 ==1) { bgcolor="#FFFFFF"; }
							$("#ReviewTRTable_"+i+"_b").append("<tr bgcolor=\""+bgcolor+"\"><td colspan=\"2\">&nbsp;</td>"
									+ "<td class=\"TRTable_Body\">"+(res_record.isPass?"通過":"失敗")+"</td>"
									+ "<td class=\"TRTable_Body\">"+res_record.sn_str+"</td>"
									+ "<td class=\"TRTable_Body\">"+res_record.reTest+"</td>"
									+ "<td class=\"TRTable_Body\">"+res_record.keyPoint+"</td>"
									+ "<td class=\"TRTable_Body\">"+res_record.successNum+"</td>"
									+ "<td class=\"TRTable_Body\">"+res_record.failNum+"</td>"
									+ "<td class=\"TRTable_Body\">"+res_record.cantNum+"</td>"
									+ "<td class=\"TRTable_Body\">"+res_record.waitNum+"</td></tr>"
							);
						});
					});
					$("#dialog-ReviewTR").prop("title","檢視測試結果 MRID: "+mrid);
					$("#dialog-ReviewTR").css("visibility", "visible");
					$("#dialog-ReviewTR").dialog( {
						resizable : true,
						width : 1000,
						height : 800,
						modal : true,
						buttons : {
							"同意" : function() {
								$("#but_" + taskID).html("已回覆");
								$("#but_" + taskID).button({disabled : true});
								conditionTR(mrid,taskID,"2",assignedTester);
								$(this).dialog("close");
							},
							"拒絕" : function() {
								$("#but_" + taskID).html("已拒絕");
								$("#but_" + taskID).button({disabled : true});
								conditionTR(mrid,taskID,"1",assignedTester);
								$(this).dialog("close");
							},
							"返回" : function() {
								$(this).dialog("close");
							}
						}
					});
				}, error : function(xhr, ajaxOptions, thrownError) {
					$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
					$("#errorMessage").append(xhr.responseText);
				}
			});
		} else if (taskDefinitionKey == "submitTR")  {	//提交測試結果
			$("tbody[id=FillinTRTable_1] tr").remove();		//先清空查詢結果，避免關閉Dialog後，再打開Dialog時，先前的東西還在
			x = $("#submitForm").serializeArray();
			$.ajax({
				type : "post",
				url : "GetApprovedTC",
				data : x,
				dataType : "JSON",
				success : function(GetApprovedTC_Result) {
					$.each(GetApprovedTC_Result, function(i, res) {
						$("#FillinTRTable_1").append(
								"<tr bgcolor=\"FFFFFF\"><td>" + res.tcID
										+ "</td><td>" + res.tcName
										+ "</td><td colspan=\"3\">" + res.tcKeyPoint
										+ "</td><td colspan=\"3\">" + res.tcProcess
										+ "</td><td colspan=\"3\">" + res.tcResExp
										+ "</td></tr>");
					});
					$("#dialog-FillinTR").prop("title","輸入測試記錄 MRID: "+mrid);
					$("#dialog-FillinTR").css("visibility", "visible");
					$("#dialog-FillinTR").dialog( {
						resizable : true,
						width : 1000,
						height : 550,
						modal : true,
						buttons : {
							"提交" : function() {
								var isChecked = submitTR_CheckChkbox();
								if (isChecked) {
									submitTR(mrid,taskID);
									$("#but_" + taskID).html("已提交");
									$("#but_" + taskID).button({disabled : true});
									$(this).dialog("close");
								} else {
									$("#dialog-message").html("提交的數據中，顯示存在未通過的結果，確定提交");
									$("#dialog-message").dialog( {
										resizable : true,
										height : 350,
										modal : true,
										buttons : {
											"確定" : function() {
												submitTR(mrid,taskID);
												$("#but_" + taskID).html("已提交");
												$("#but_" + taskID).button({disabled : true});
												$(this).dialog("close");
											},
											"返回" : function() {
												$(this).dialog("close");
											}
										}
									});
								}
								$(this).dialog("close");
								$("#dialog-FillinTR").dialog("destroy");
							},
							"返回" : function() {
								$(this).dialog("close");
							}
						}
					});
				}, error : function(xhr, ajaxOptions, thrownError) {
					$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
					$("#errorMessage").append(xhr.responseText);
				}
			});
		} else {	//指派測試工作 或 送審測試案例
			var KeyText = getKeyText(taskDefinitionKey);
			var bstr = $("#but_" + taskID).attr("butValue");	//按鈕上的文字
			var token = bstr.substring(3, bstr.length);
			if (bstr.indexOf(KeyText) > -1) {
				var userID = $.cookie("userID"); 
				var url = "";
				var resulText = "";
				if (taskDefinitionKey == "submitTC") {
					url = "SubmitTC";
					resulText = "成功送出";
				} else if (taskDefinitionKey == "dispatchTask") {
					url = "SubmitSelectTester";
					resulText = "已委由" + token + "處理"
				}
				$("#dialog-message").html("MRID為" + mrid + "的工作<br/>確定選擇：" + token);
				$("#dialog:ui-dialog").dialog("destroy");
				$("#dialog-message").dialog( {
					resizable : true,
					height : 350,
					modal : true,
					buttons : {
						"確定" : function() {
						$("#submitTaskID")[0].value = taskID;
						$("#submitSelectedTester")[0].value = token;
						$("#submitTCID")[0].value = token;
						$("#submitprocessInstanceID")[0].value = processInstanceID;
						$("#submitOri_performerId")[0].value = ori_performerId;
						$("#submitMRID")[0].value = mrid;
						$("#submitVer_d")[0].value = ver_d;
						x = $("#submitForm").serializeArray();
						$.ajax({
							type : "post",
							url : url,
							data : x,
							dataType : "text",
							success : function(submitResult) {
								if (submitResult == "OK") {
									$("#but_" + taskID).html(resulText);
									$("#but_" + taskID).button({disabled : true});
								} else {
									$("#errorMessage").html(submitResult);
								}
							}, error : function(xhr, ajaxOptions, thrownError) {
								$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
								$("#errorMessage").append(xhr.responseText);
							}
						});
						$(this).dialog("close");
					},
					"返回" : function() {
						$(this).dialog("close");
					}
				}
			});
		} else {
			if(taskDefinitionKey == "dispatchTask") {	//指派測試工作
				x = $('#submitForm').serializeArray();
				$.ajax({
					type : "post",
					url : "GetTester",
					data : x,
					dataType : "JSON",
					success : function(queryResult) {
						$(".selectList").remove(); //先把舊的li移掉
						$.each(queryResult, function(i, res) {
							$("#popUL_b").append("<li sn='"+res.id+"' class=\"selectList\">" + res.id + "</li>");
						});
						$("#popUL_b").selectable();
						$("#dialog-DispatchTask").css("visibility", "visible");
						$("#dialog-DispatchTask").dialog({
							resizable : false,
							width : 500,
							height : 400,
							modal : true,
							buttons : {
								"關閉" : function() {
									var content = "將指派";
									var size = $(".ui-selected").size();
									for (i=0;i<=size;i++) {
										content +=  "<br/>";
										content +=  $(".ui-selected").eq(i).text();
									}
									$("#but_" + taskID).html(content);
									$("#but_" + taskID).attr("butValue",content);
									$(this).dialog("close");
								}
							}
						});
					}, error : function(xhr, ajaxOptions, thrownError) {
						
						$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
						$("#errorMessage").append(xhr.responseText);
					}
				});

				$("#dialog:ui-dialog").dialog("destroy");
			} else if(taskDefinitionKey == "submitTC") {	//送審測試案例
				dialogOpen(taskID);
			} 
		}	
	}
}
	
	function dialogOpen(taskID) {
		$.each($(".require_from_group"), function(i, val) { //將每個欄位都設為空字串
			val["value"] = "";
		});
		$("#activeTaskID")[0].value= taskID;			//打開Dialog前，先把發動這個視窗的taskID記錄下來
		$("tbody[id=popTable_b] div tr").remove();		//先清空查詢結果，避免關閉Dialog後，再打開Dialog時，先前的東西還在
		$("#q_message").html("");					//效果不太一樣，頂著先
		$("#QueryTC_Result").css("visibility", "hidden");
		$("#dialog-QueryTC").css("visibility", "visible");
		/** 測試案例查詢的條件輸入框 **/ 
		$("#dialog-QueryTC").dialog({
			autoOpen : true,
			height : 420,
			width : 680,
			modal : true,
			buttons : {
			"送出" : function() {
				var isNotBlank = 0;
				var str = "";
				$.each($(".require_from_group"), function(i, val) {
					str = str + val["value"]; // val是一個物件，若要取得物件中的值，需指定要屬性的名稱，也可以寫成val.value
					if (!($.trim(val["value"]) == "")) {
						isNotBlank = 1;
					}
				});
							
				$("#popTable_b").html("");
				if (isNotBlank == 0) {
					$("#q_message").html("請至少輸入一個查詢欄位");
				} else { //表示有輸入，要開始查詢
				$("#q_message").html("");	//效果不太一樣，頂著先
				x = $("#qTC_form").serializeArray();
				$.ajax({
					type : "post",
					url : "QueryTC",
					data : x,
					dataType : "JSON",
					success : function(queryResult) {
						if (queryResult.strSQL[0]["result"] == "No Result") {
							$("q_message").html("沒找到!!");
						} else {	//表示有找到符合條件的測試案例
						$.each(	queryResult.sqlData,function(i,res) {
							var bgcolor="#CCCCCC";
							if ((i+1) % 2 ==1) { bgcolor="#FFFFFF"; }
							var tcID = res.tcID;
							$("#popTable_b").append(
								"<tr bgcolor=\""+bgcolor+"\"><td>" + (i+1)
								+ "</td><td><input type=\"button\" onClick=\"selectTC('"+tcID +"')\" value=\"選\" />"
								+ "</td><td>" + tcID
								+ "</td><td>" + res.tcName
								+ "</td><td>" + res.CreatedDateTime
								+ "</td><td>" + res.Creator
								+ "</td></tr>");
							});
							$("#QueryTC_Result").css("visibility", "visible");
						}
					}
				});
			}
			},"關閉" : function() {
				$(this).dialog("close");
			}
		}
	});
	}
	
	/** 決定不同類型的Task，它們上面的文字 **/
	function getKeyText(taskDefinitionKey){
		var str = "";
		switch (taskDefinitionKey) {
			case "submitTC":
				str = "將送審";
				break;
			case "dispatchTask":
				str = "將指派";
				break;		
		}
		return str;
	}
	
	/** 查詢簽核歷史資訊 **/
	function query_processHis(processInstanceID,mrid) {
		$("tbody[id=his_queryTable_b] tr").remove();		//先清空查詢結果，避免關閉Dialog後，再打開Dialog時，先前的東西還在
		$("#submitprocessInstanceID")[0].value = processInstanceID;
		$("#submitQueryMRID")[0].value = mrid;
		$("#his_queryTask").prop("title","MRID: "+mrid+"簽核記錄");
		x = $("#submitForm").serializeArray();
		$.ajax({
			type : "post",
			url : "Query_ProcessHis",
			data : x,
			dataType : "JSON",
			success : function(ReviewTC_01Result) {
				$.each(ReviewTC_01Result, function(i, res) {
					var bgcolor = "#CCCCCC";
					if ((i + 1) % 2 == 1) {
						bgcolor = "#FFFFFF";
					}
					$("#his_queryTable_b").append(
							"<tr bgcolor=\""+bgcolor+"\"><td>" + (i+1)
									+ "</td><td>" + res.taskName
									+ "</td><td>" + (res.assignee == undefined?"":res.assignee)
									+ "</td><td>" + (res.startTime == undefined?"":res.startTime)
									+ "</td><td>" + (res.endTime == undefined?"":res.endTime)
									+ "</td><td>" + (res.comment == undefined?"":res.comment)
									+ "</td></tr>");
				});
				$("#his_queryTask").css("visibility", "visible");
				$("#his_queryTask").dialog({
					resizable : true,
					width : 800,
					height : 400,
					modal : true,
					show: "slide",
					buttons : {
						"關閉" : function() {
							$(this).dialog("close");
						}
					}
				});
			}
		});
	}
	
	
	/** 登出 **/
	function logout(){
		$.cookie("userID", null);
		$.cookie("userName", null);
		$.cookie("password", null);
		$.cookie("roleList", null);
		window.location.reload();
	}
	
	//案例管理
	function manageTC() {
		window.open('Pluto.html','textfile',config='height=500,width=750,menubar=1,location=no');
	}
	
	function deleteResult(row) {
		var rowspan = $("#resultComment").prop("rowspan");
		rowspan = Number(rowspan) - 1;
		$("#resultComment").prop("rowspan",rowspan);
		$("#tr_"+row).remove();
		refUI();
	}
	
	/* 重新Refresh畫面 */
	function refUI() {
		var num = $(".resultBody").size()+2;
		
		for (ini =2; ini <num; ini++) {
			$("tr.resultBody td:nth-child(2)")[ini-2].innerHTML = ini;
		}
		$('tr.resultBody:odd').attr('bgcolor','#CCCCCC');		//灰色
		$('tr.resultBody:even').attr('bgcolor','#FFFFFF');		//白色
	}
	
	/** 初始頁面時執行  **/
	$(document).ready(function() {

		/** 畫面起始時，先將查詢結果的Table藏起來 **/
		$(".queryTask").css("visibility", "hidden");
		/** 畫面起始時，先將檢視測試案例的Table藏起來 **/
		$("#dialog-ReviewTC").css("visibility", "hidden");
		/** 畫面起始時，先將指派工作的Table藏起來 **/
		$("#dialog-DispatchTask").css("visibility", "hidden");
		/** 畫面起始時，先將測試案例查詢條件Table藏起來 **/
		$("#dialog-QueryTC").css("visibility", "hidden");
		/** 畫面起始時，先將測試案例查詢結果Table藏起來 **/
		//$("#QueryTC_Result").css("visibility", "hidden");
		/** 畫面起始時，先將簽核歷史紀錄的Table藏起來 **/
		$("#his_queryTask").css("visibility", "hidden");
		$("#dialog-FillinTR").css("visibility", "hidden");
		$("#dialog-ReviewTR").css("visibility", "hidden");
		
		
		$("#isPassCheckALL").bind("click",function(){
			if ($("#isPassCheckALL").is(":checked")) {
				$(".isPass").each(function() {
					$(this).prop("checked",true);
				}); 
			} else {
				$(".isPass").each(function() {
					$(this).prop("checked",false);
				});
			}
		});
		
		$("#addTRCont").bind("click", function() {
			var rowspan = $("#resultComment").prop("rowspan");
			rowspan = Number(rowspan) + 1;
			$("#resultComment").prop("rowspan",rowspan);
			
			var bgcolor = "#CCCCCC";
			if ((rowspan + 1) % 2 == 1) {
				bgcolor = "#FFFFFF";
			}
			var checkbox = "<input type=\"checkbox\" class=\"isPass\" checked/>";
			var str = "<tr class=\"resultBody\" bgcolor=\""+bgcolor+"\"><td>"+checkbox
			+ "</td><td class=\"rowIndex\">" + rowspan
			+ "</td><td><input name=\""+ rowspan +"_reTest\" type=\"text\" maxlength=\"2\" size=\"1\" onkeyup=\"return ValidateNumber(this,value)\" />"
			+ "</td><td><input name=\""+ rowspan +"_keyPoint\" type=\"text\" maxlength=\"2\" size=\"1\" onkeyup=\"return ValidateNumber(this,value)\" />"
			+ "</td><td><input name=\""+ rowspan +"_successNum\" type=\"text\" maxlength=\"2\" size=\"1\" onkeyup=\"return ValidateNumber(this,value)\" />"
			+ "</td><td><input name=\""+ rowspan +"_failNum\" type=\"text\" maxlength=\"2\" size=\"1\" onkeyup=\"return ValidateNumber(this,value)\" />"
			+ "</td><td><input name=\""+ rowspan +"_cantNum\" type=\"text\" maxlength=\"2\" size=\"1\" onkeyup=\"return ValidateNumber(this,value)\" />"
			+ "</td><td><input name=\""+ rowspan +"_waitNum\" type=\"text\" maxlength=\"2\" size=\"1\" onkeyup=\"return ValidateNumber(this,value)\" />"
			+ "</td><td><button type=\"button\" onclick=\"deleteResult("+rowspan+")\">刪除</button>"
			+ "</td></tr>";
			$("#FillinTRTable_b").append(str);
		});
		
		
		/** 登入的按鈕 **/
		$("#loginButton").bind("click", function() {
			var userID = $("#userID")[0].value;
			var password = $("#password")[0].value;

			if ($.trim(userID) == "") {
				$("#errorMessage").html("沒有輸入User ID!");
			} else if ($.trim(password) == "") {
				$("#errorMessage").html("沒有輸入Password!");
			} else {
				x = $("#loginForm").serializeArray();
				$.ajax({
					type : "post",
					url : "Auth",
					data : x,
					dataType : "json",
					success : function(queryResult) {
						if (queryResult.status == 1) { //身份核對正常，且擁有權限
							window.location = "workList.html";
							var nickName = queryResult.nickName;
							$.cookie("userName", nickName);
							$.cookie("userID", userID);
							$.cookie("password", password);
							var roleList= "";
							$.each(queryResult.roleLists, function(i, res) {
								if (i != queryResult.roleLists.length ) {
									roleList += (res + "||");
								}
							});
							$.cookie("roleList", roleList);
						} else {
							$.cookie("userID", null);
							$("#errorMessage").html(queryResult.message);
						}
					}, error : function(xhr, ajaxOptions, thrownError) {
						$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
						$("#errorMessage").append(xhr.responseText);
					}
				});
			}
		});
		
		
		/** 建立跳出視窗中的datepicker **/
		$('input[id$=Date]').datepicker({
			dateFormat : 'yy-mm-dd'
		});
		
		
		/** 在畫面初始時，如果Cookie中，仍存在使用者的值，則直接送出，不用再輸入 **/
		if ($.cookie("userID") != undefined || $.cookie("userID") != null) {
			$("#userID")[0].value = $.cookie("userID");
			$("#password")[0].value = $.cookie("password");
			$("#submitUser")[0].value = $("#userID")[0].value;
			$("#loginButton").click();
		}
		
		/** 將游標設定在輸入框中 **/
		$("input[type='text']:first", document.forms[0]).focus();
		
		
	});

	
	
</script>
<title>歡迎使用TMS</title>
</head>
<body>
	<!-- 驗證使用者帳密 -->
	<div id="login" class="forLogin">
		<form id="loginForm" action="post">
			<table>
				<tr>
					<th colspan="2">Welcome to use TMS!</th>
				</tr>
				<tr>
					<th><label for="userID">User ID</label></th>
					<td><input type="text" id="userID" name="userID"
						maxLength="15" size="15" /></td>
				</tr>
				<tr>
					<th><label for="password">Password</label></th>
					<td><input type="password" id="password" name="password" maxLength="15" size="15" /></td>
				</tr>
			</table>
		</form>
	</div>
	<p>
		<button type="button" id="loginButton" class="forLogin">Log in</button>
	<p>
	<div id="message"></div>
	
	<!-- 查詢工作作清單的結果 -->
	<div class="queryTask">
		<table id="resultTable">
			<thead id="resultTable_h">
				<tr>
					<th>#</th>
					<th>&nbsp;</th>
					<th>MRID</th>
					<th>執行工作</th>
					<th>取得時間</th>
					<th>記錄</th>
				</tr>
			</thead>

			<tbody id="resultTable_b">
			</tbody>
		</table>
	</div>
	<p>
	
	<!-- 錯誤訊息顯示 -->
	<div id="errorMessage" class="alertText"></div>
	<!-- 完成訊息顯示 -->
	<div id="successMessage" class="messageText"></div>
	
	
	<div id="dialog-DispatchTask" title="請選擇測試人員">
		<form method="post">
			<fieldset>
				<ul id="popUL_b">
				</ul>
			</fieldset>
		</form>
	</div>
	
	<div id="dialog-ReviewTC" title="待審案例">
		<form method="post">
			<fieldset>
				<table id="ReviewTCTable">
					<thead id="ReviewTCTable_h">
						<tr>
							<th>案例ID</th>
							<th>案例名稱</th>
							<th>驗証重點</th>
							<th>測試程序</th>
							<th>預期結果</th>
							<th>提出日期</th>
							<th>提出者</th>
						</tr>
					</thead>

					<tbody id="ReviewTCTable_b">
					</tbody>
				</table>
				<h2>簽核意見：</h2>
				<TEXTAREA id="reviewTC_Comment" ></TEXTAREA>
			</fieldset>
		</form>
	</div>
	
	<!-- 測試結果輸入的區塊 -->
	<div id="dialog-ReviewTR" title="測試結果">
		<table id="ReviewTRTable" class="FillinTRTable" >
		</table>
		<h2>簽核意見：</h2>
		<TEXTAREA id="reviewTR_Comment" ></TEXTAREA>
	</div>
	
	
	<!-- 測試結果輸入的區塊 -->
	<div id="dialog-FillinTR" title="輸入測試結果">
		<form id="tr_Form" action="post">
			<table class="FillinTRTable" >
				<thead id="FillinTRTable_h_1">
					<tr>
						<th>案例ID</th>
						<th>案例名稱</th>
						<th colspan="3">驗証重點</th>
						<th colspan="3">測試程序</th>
						<th colspan="3">預期結果</th>
					</tr>
				</thead>
				<tbody id="FillinTRTable_1">
				</tbody>
			</table>
			<p><p>
			<table class="FillinTRTable" >
				<thead>
				</thead>
				<tbody id="FillinTRTable_b" class="TRTable_Body">
					<tr>
						<td>備註</td>
						<td>
							<button type="button" id="addTRCont">新增測試結果</button></td>
						<td class="TRTable_Record_h_1">通過</td>
						<td class="TRTable_Record_h_1">合計</td>
						<td class="TRTable_Record_h_1">&nbsp;</td>
						<td class="TRTable_Record_h_1">&nbsp;</td>
						<td class="TRTable_Record_h_1">&nbsp;</td>
						<td class="TRTable_Record_h_1">&nbsp;</td>
						<td class="TRTable_Record_h_1">&nbsp;</td>
						<td class="TRTable_Record_h_1">&nbsp;</td>
						<td class="TRTable_Record_h_1">&nbsp;</td>
					</tr>
					<tr class="FillinTRTable_l_1">
						<td colspan="2">
							<textarea id="FillCommentArea" name="FillCommentArea"></textarea>
						</td>
						<td class="TRTable_Body">
							<input type="checkbox" id="isPassCheckALL" />
						</td>
						
						<td class="TRTable_Body">#</td>
						<td class="TRTable_Body">缺失數</td>
						<td class="TRTable_Body">驗證重點數</td>
						<td class="TRTable_Body">成功數</td>
						<td class="TRTable_Body">失敗數</td>
						<td class="TRTable_Body">無法測試數</td>
						<td class="TRTable_Body">待測試數</td>
						<td class="TRTable_Body">&nbsp;</td>
					</tr>
					<tr bgcolor="#CCCCCC" class="resultBody" >
						<td id=resultComment rowspan="1" colspan="2" bgcolor="#FFFFFF" class="FillinTRTable_l_2">
							<input type="file" class="multi" id="T7" name="t7" />
						</td>
						<td><input name="1_isPass"  type="checkbox" checked class="isPass" /></td>
						<td>1</td>
						<td><input type="text" name="1_reTest" maxlength="2" size="1" onkeyup="return ValidateNumber(this,value)" /></td>
						<td><input type="text" name="1_keyPoint" maxlength="2" size="1" onkeyup="return ValidateNumber(this,value)" /></td>
						<td><input type="text" name="1_successNum" maxlength="2" size="1" onkeyup="return ValidateNumber(this,value)" /></td>
						<td><input type="text" name="1_failNum" maxlength="2" size="1" onkeyup="return ValidateNumber(this,value)" /></td>
						<td><input type="text" name="1_cantNum" maxlength="2" size="1" onkeyup="return ValidateNumber(this,value)" /></td>
						<td><input type="text" name="1_waitNum" maxlength="2" size="1" onkeyup="return ValidateNumber(this,value)" /></td>
						<td>&nbsp;</td>
					</tr>
				</tbody>
			</table>
			<input type="hidden" id="trMRID" name="trMRID" />
			<input type="hidden" id="trUser" name="trUser" />
			<input type="hidden" id="trNumSN" name="trNumSN" />
			<input type="hidden" id="trTaskID" name="trTaskID" />
		</form>
	</div>
		
	
	
	
	
	<!-- 查詢簽核歷史紀錄 -->
	<div id="his_queryTask" title="">
		<table id="his_queryTable">
			<thead id="his_queryTable_h">
			<tr>
			<th id="his_queryTask_proInsID" colspan="6"></th>
			</tr>
				<tr>
					<th>#</th>
					<th>執行工作</th>
					<th>執行者</th>
					<th>取得時間</th>
					<th>送出時間</th>
					<th>簽核意見</th>
				</tr>
			</thead>

			<tbody id="his_queryTable_b">
			</tbody>
		</table>
	</div>
	
	<!-- 查詢測試案例的Table -->
	<div id="dialog-QueryTC" title="請輸入查詢條件">
		<form id="qTC_form" method="post">
			<fieldset>
				<table>
					<tr>
						<th width="150" valign="middle" bgcolor="#6699FF" scope="col">
							<div align="right">測試案例ID：</div>
						</th>
						<th scope="col"><div align="left">
								<input type="text" name="q_tcID" id="q_tcID"
									class="require_from_group text ui-widget-content ui-corner-all" />
							</div></th>
					</tr>
					<tr>
						<th width="150" valign="middle" bgcolor="#6699FF"><div
								align="right">測試案例名稱：</div></th>
						<td bgcolor="#CCCCCC"><input type="text" name="q_tcName"
							id="q_tcName"
							class="require_from_group text ui-widget-content ui-corner-all" /></td>
					</tr>
					<tr>
						<th width="150" valign="middle" bgcolor="#6699FF"><div
								align="right">繼承自：</div></th>
						<td><input type="text" id="q_parentTCID" name="q_parentTCID"
							class="require_from_group text ui-widget-content ui-corner-all" /></td>
					</tr>
					<tr>
						<th width="150" valign="middle" bgcolor="#6699FF"><div
								align="right">建立者：</div></th>
						<td bgcolor="#CCCCCC"><input type="text" name="q_creator"
							id="q_creator"
							class="require_from_group text ui-widget-content ui-corner-all" /></td>
					</tr>
					<tr>
						<th width="150" rowspan="2" valign="middle" bgcolor="#6699FF"><div
								align="right">建立日期：</div>
							<div align="right"></div></th>
						<td>起：<input type="text" name="q_fromDate" id="q_fromDate"
							class="require_from_group text ui-widget-content ui-corner-all" />
						</td>
					</tr>
					<tr>
						<td bgcolor="#CCCCCC">迄：<input type="text" name="q_toDate"
							id="q_toDate"
							class="require_from_group text ui-widget-content ui-corner-all" /></td>
					</tr>
					<tr>
						<td bgcolor="#6699FF">&nbsp;</td>
						<td id="q_message"
							class="require_from_group text ui-widget-content ui-corner-all">&nbsp;</td>
					</tr>
				</table>

				<div id="QueryTC_Result">
					<hr />
					<table id="popTable">
						<thead id="popTable_h">
							<tr>
								<th>#</th>
								<th>&nbsp;</th>
								<th>測試案例ID</th>
								<th>案例名稱</th>
								<th>建立日期</th>
								<th>建立者</th>
							</tr>
						</thead>
						<tbody id="popTable_b">
						</tbody>
					</table>
				</div>
			</fieldset>
		</form>
	</div>
	
	<!-- 畫面上我用JQuery 控制不了的變數 -->
	<input type="hidden" id="activeTaskID" name="activeTaskID" />
	
	<!-- 放置查詢用的變數 -->
	<form id="submitForm">
		<input type="hidden" id="submitUser" name="submitUser" />
		<input type="hidden" id="submitMRID" name="submitMRID" />
		<input type="hidden" id="submitQueryMRID" name="submitQueryMRID" />
		<input type="hidden" id="submitTaskID" name="submitTaskID" />
		<input type="hidden" id="submitTCID" name="submitTCID" />
		<input type="hidden" id="submitCondition" name="submitCondition" />
		<input type="hidden" id="submitprocessInstanceID" name="submitprocessInstanceID" />
		<input type="hidden" id="submitAssignedTester" name="submitAssignedTester" />
		<input type="hidden" id="submitSelectedTester" name="submitSelectedTester" />
		<input type="hidden" id="submitComment" name="submitComment" />
		<input type="hidden" id="submitOri_performerId" name="submitOri_performerId" />
		<input type="hidden" id="submitVer_d" name="submitVer_d" />
	</form>
	
	
	
	<!-- 確認對話框  -->
	<div id="dialog-message" title="確認"></div>
	
</body>
</html>